package com.juku2024.juku.db.dao

import android.text.TextUtils
import androidx.room.TypeConverter
import com.juku2024.juku.model.HotSearchItemModel
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class HotConverters {

    @TypeConverter
    fun stringToList(value: String?): ArrayList<HotSearchItemModel>? {
        return if (TextUtils.isEmpty(value)) {
            null
        } else {
            val listType = object : TypeToken<ArrayList<HotSearchItemModel>>() {}.type
            Gson().fromJson(value, listType)
        }

    }

    @TypeConverter
    fun listToString(list: ArrayList<HotSearchItemModel>?): String? {
        return if (list?.isNotEmpty() == true) {
            Gson().toJson(list)
        } else {
            null
        }
    }

}